package com.gack.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.gack.business.service.HelpCenterServiceInterface;
import com.gack.helper.common.AjaxJson;
import com.gack.helper.common.abstractobj.ApiController;

import io.swagger.annotations.ApiOperation;
/**
 * HelpCenterController 帮助中心接口
 * @author lsy
 *
 */
@RestController
@RequestMapping(ApiController.HELP_CENTRE)
public class HelpCenterController {
	
	@Autowired
	private HelpCenterServiceInterface centerServiceInterface;
	/**
	 * addHelpCenter 增加一条帮助信息
	 * @param title 标题
	 * @param question 问题
	 * @param content 内容
	 * @param status 状态 0 禁用 1 启动
	 * @param uid 创建者userid
	 * @return
	 */
	@ApiOperation("增加帮助中心")
	@PostMapping("/addHelpCenter")
	public AjaxJson addHelpCenter(String title, String question, String content, Integer status, String uid, String id) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.addHelpCenter(title, question, content, status, uid, id));
		} catch (Exception e) {
			e.printStackTrace();
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	
	/**
	 * changeStatus 更改帮助信息状态
	 * @param status 0 禁用 1 启用
	 * @param id
	 * @return
	 */
	@ApiOperation("修改状态")
	@PostMapping("/changeStatus")
	public AjaxJson changeStatus(Integer status, String id, String uid) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.changeStatus(status, id, uid));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	
	/**
	 * deleteHelpCenter 删除一条帮助中心
	 * @param id 
	 * @return
	 */
	@ApiOperation("删除信息")
	@PostMapping("/deleteHelpCenter")
	public AjaxJson deleteHelpCenter(String id, String uid) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.deleteHelpCenter(id, uid));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	
	/**
	 * findHelpCenter 查询详情
	 * @param id
	 * @return
	 */
	@ApiOperation("查询详情")
	@PostMapping("/findHelpCenter")
	public AjaxJson findHelpCenter(String id) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.findHelpCenter(id));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	
	/**
	 * findHelpCenterList 分页查询帮助中心
	 * @param page
	 * @param size
	 * @return
	 */
	@ApiOperation("分页查询")
	@PostMapping("/findHelpCenterList")
	public AjaxJson findHelpCenterList(@RequestParam(value = "page", defaultValue = "0") Integer page,
            @RequestParam(value = "size", defaultValue = "10") Integer size) {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.findHelpCenterList(page, size));
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	
	@ApiOperation("前端获取全部帮助中心")
	@PostMapping("/getAllHelp")
	public AjaxJson getAllHelp() {
		AjaxJson ajaxJson = new AjaxJson();
		try {
			ajaxJson.setSuccess(true).setStatus(200).setData(centerServiceInterface.getAllHelp());
		} catch (Exception e) {
			ajaxJson.setSuccess(false).setStatus(500).setMsg("操作失败");
			
		}
		return ajaxJson;
	}
	

}
